package cn.op.portal.category.action;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

import cn.op.portal.category.domain.Category;
import cn.op.portal.category.service.CategoryService;
import cn.op.portal.common.action.BaseAction;
import cn.op.portal.common.vo.Page;
import cn.op.portal.towel.domain.Towel;

public class CategoryAction extends BaseAction implements ModelDriven<Category>, Preparable{
	@Resource
	private CategoryService categoryService;
	
	private Integer id;
	private Category category;
	private Page page;

	
	public String addUI() {
//		List<Category> categorys = categoryService.getAll();
//		getRequest().setAttribute("categorys", categorys);
		return "addUI";
	}
	
	public String updateUI() {
//		List<Category> categorys = categoryService.getAll();
//		getRequest().setAttribute("categorys", categorys);
		return "updateUI";
	}
	
	public String add(){
		categoryService.add(category);
		return SUCCESS;
	}
	
	public String deleteById(){
		categoryService.deleteById(id);
		return null;
	}
	
	public String update() {
		categoryService.update(category);
		return SUCCESS;
	}

	public String findById(){
		category = categoryService.findById(id);
		return SUCCESS;
	}
	
	public String findPage() throws Exception{
		page = categoryService.findPage(pageNum,pageSize);
		return SUCCESS;
	}
	
	
	@Override
	public void prepare() throws Exception {
		if(id==null) {
			category = new Category();
		} else {
			category = categoryService.findById(id);
		}
	}

	@Override
	public Category getModel() {
		return category;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Category getCategory() {
		return category;
	}

	public void setCategory(Category category) {
		this.category = category;
	}

	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}
	
	
}
